package com.example.haoyundaoyonghu.base;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import com.example.haoyundaoyonghu.R;
import com.example.haoyundaoyonghu.dialog.MyWalletDialog;
import com.example.haoyundaoyonghu.dialog.ShowDialog;
import com.gyf.barlibrary.ImmersionBar;

import butterknife.ButterKnife;
import butterknife.Unbinder;


@SuppressLint("Registered")
public abstract class BaseActivity extends AppCompatActivity {

    public MyWalletDialog walletDialog;

    private ShowDialog showDialog;


  private Context context;


    protected Unbinder unbinder;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setLayoutId());
        initStatusBar();
        unbinder = ButterKnife.bind(this);
        init();
    }
    protected abstract int setLayoutId();
    /**
     * 设置状态栏颜色
     */
    protected void setSystemBarColor(int color) {
        ImmersionBar.with(this).statusBarColor(color);
    }
    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    public static void setTranslucent(Activity activity) {
        // 设置状态栏透明
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    protected abstract void init();
    //屏幕变暗，变亮效果
    private void setBgAlpha(float bgAlpha) {
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.alpha = bgAlpha;
        //alpha在0.0f和1.0f之间，1.0f完全不暗，0.0f全暗
        if (bgAlpha == 1) {
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        } else {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }
        getWindow().setAttributes(attributes);
    }
    /**
     * @author Zander  @data 2020.12.17
     * 初始化状态栏
     */
    public void  initStatusBar(){
        Bar.setWindowStatusBarColor(this, R.color.white);
        Bar.changStatusIconCollor(true,this);  //T  未黑色
    }
    public  void setPayDialog(View.OnClickListener onClick){
        walletDialog = new MyWalletDialog(this);
        walletDialog.setPayDialog(onClick);
        walletDialog.setCanceledOnTouchOutside(false);
        walletDialog.show();
    }










    /**
     * 通用消息
     * @param tit 标题
     * @param msg 消息
     * @param onClick  点击事件
     */
    public void setShowDialog(String tit,String msg,View.OnClickListener onClick){
        showDialog = new ShowDialog(this);
        showDialog.setShowDialog(tit,msg,onClick);
        showDialog.setCanceledOnTouchOutside(false);
        showDialog.show();
    }





    /**
     * 保持不息屏
     */
    protected void keepScreenOn() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }
    /**
     * 全屏
     */
    protected void setFullScreen() {
        ImmersionBar.with(this).init();
    }
    /**
     *  继承者直接调用（这里就是哥特半封装， setShareDialog() 这个方法是向外部暴露，传入相关的参数）
     *  ）
     */


    @Override
    protected void onDestroy() {
        super.onDestroy();

        unbinder.unbind();
    }



}
